package com.skyinno.mrms.station.controller;

import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.skyinno.mrms.common.controller.BaseController;
import com.skyinno.mrms.common.model.JsonModel;
import com.skyinno.mrms.station.model.FileView;
import com.skyinno.mrms.station.model.QueryView;
import com.skyinno.mrms.station.model.View;
import com.skyinno.mrms.station.service.StationTypeService;
import com.skyinno.mrms.utils.FrameException;

@RestController
@RequestMapping("/manage/mapStationType")
public class StationTypeController extends BaseController {

	@Autowired
	private StationTypeService service;

	@RequestMapping(value = "/stationTypeList.html")
	public String mapInfo(ModelMap modelMap) throws Exception {
		modelMap.addAttribute("eventId", "111");
		return "manage/mapStationType/list";
	}
	
	@RequestMapping(value = "/queryPage.json", method = RequestMethod.POST)
	public Map<String, Object> queryPage(QueryView view) {
		Map<String, Object> map = service.queryPage(view);
		return map;
	}

	@RequestMapping(value = "/remove.json", method = RequestMethod.POST)
	public JsonModel remove(String ids) throws FrameException {
		return new JsonModel(true, service.remove(ids));
	}

	@RequestMapping(value = "/add.json", method = RequestMethod.POST)
	public JsonModel add(View view, Locale locale) throws Exception {
		return new JsonModel(true, service.add(view, locale));
	}

	@RequestMapping(value = "/addPermission.json", method = RequestMethod.POST)
	public void addPermission(HttpServletRequest request, View view, ModelMap modelMap) throws Exception {
		super.setResponse(modelMap, true, null);
	}
	
	@RequestMapping(value = "/modify.json", method = RequestMethod.POST)
	public JsonModel modify( View view, Locale locale) throws Exception {
		return new JsonModel(true, service.modify(view, locale));
	}

	@RequestMapping(value = "/view.json", method = RequestMethod.POST)
	public Map<String, Object> view(String id) throws FrameException {
		Map<String, Object> map = service.view(id);
		return map;
	}
	
	@PostMapping(value = "/uploadFile.plain")
	public FileView uploadFile(@RequestParam("file")MultipartFile file, ModelMap modelMap) throws Exception {
		FileView fileView = service.stationTypeUploadIcon(file);
		return fileView;
	}
}
